<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<link rel="stylesheet"  href="/layui/css/layui.css"/>
<meta charset="UTF-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>地市推广代理审核</title>
</head>
<body>
<script src="/plugins/jquery/jquery-1.10.2.min.js"></script>
<script  src="/layui/layui.js"></script>
<script src="/plugins/js/common.js"></script>
<form class="layui-form">
	<label class="layui-form-label">登录名</label>
    <div class="layui-input-inline">
        <input type="text" name="loginName" id="loginName" autocomplete="off"  placeholder="请输入登录名" class="layui-input">
    </div>
    <div class="layui-inline">
			 <button class="layui-btn" data-type="reload" id="searchButton" onclick="return search();">搜索</button> &nbsp;
          </div>
    <div style="margin-left: 5px;">
    		 <br>
	          <button class="layui-btn layuiadmin-btn-replys" onclick="return toAppUserDetail();">查看用户详情</button>&nbsp;
	  </div>      
</form>
<table class="layui-hide" id="appUserList"  lay-filter="appUserList"></table>
<script type="text/html" id="userBarAction" th:inline="javascript">
  <a class="layui-btn layui-btn-xs" lay-event="edit">审核通过</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">审核不通过</a>
</script>
<script type="text/javascript">
var table;
var layer;
layui.use(['table'], function(){
	layer=layui.layer;
	  table = layui.table;
	  tableIns = initTable(table);
	//监听行工具事件
	  table.on('tool(appUserList)', function(obj){
		  
	    var data = obj.data;
	    if(data.cityPromotionCheckStatus!=1){
	    	 layMsg("审核状态不是待审核",2000);
	    	 return;
	       }
	    if(data.appUserType!=2){
	    	 layMsg("操作失败，用户类型必须为VIP用户",2000);
	    	 return;
	       }
	    if(obj.event === 'del'){
	       updateCityPromotionCheckStatus(3,data.id);
	    } else if(obj.event === 'edit'){
	       updateCityPromotionCheckStatus(2,data.id);
	    }
	  });
});

/**
 * 1、待审核 2、审核通过 3、审核不通过 
 */
function updateCityPromotionCheckStatus(status,id){
	var msg = (status == 2 ?"确认要把该用户设置为地市推广代理吗？":"确认要把该用户地市推广代理的申请驳回吗？");
	var param;
	if(status == 2){
		param={id:id,cityPromotionCheckStatus:status,appUserType:3};
	}else{
		param={id:id,cityPromotionCheckStatus:status};
	}
	layer.confirm(msg, {
		  btn: ['确认','取消'] //按钮
		}, function(){
			var result = ajaxAction('/appUser/updateAppUserInfo',param);
			if(result){
				search("操作成功");
			}else{
				search("操作失败");
			}
		});
}

function initTable(){
	table.render({
	    elem: '#appUserList',
	    url:"/appUser/listData?cityPromotion=1",
	    cellMinWidth: 50,
	    cols:[
		    	[
		    	  {type:'checkbox',field:'id'},	
			      {field:'loginName'  ,title: '登录名'},
			      {field:'mobile',  title: '手机号'},
			      {field:'areaName', title: '所属区域'},
			      {field:'appUserType',  title: '用户类型',templet:function(value){
			    	  if(value.appUserType==1){
			    		  return "普通用户";
			    	  }else if(value.appUserType==2){
			    		  return "VIP会员";
			    	  }else{
			    		  return "地市推广代理";
			    	  }
			      	}
			      },
			      {field:'createDate',  title: '注册时间',sort : true,fixed:false,templet:'<div>{{ formatDate(d.createDate)}}</div>'},
			      {field:'state',  title: '用户状态',templet:function(value){
			    	  if(value.state==1){
			    		  return "正常";
			    	  }else{
			    		  return "锁定";
			    	  }
			      	}
			      },
			      {field:'cityPromotionCheckStatus',  title: '审核状态',templet:function(value){
			    	  if(value.cityPromotionCheckStatus==1){
			    		  return "待审核";
			    	  }else if(value.cityPromotionCheckStatus==2){
			    		  return "审核通过";
			    	  }else if(value.cityPromotionCheckStatus==3){
			    		  return "审核不通过";
			    	  }
			      	}
			      },
			      {fixed: 'right', title:'操作', toolbar: '#userBarAction'}
		    	]
	    ],page: true,
	    limit:8,
	    where: {
		    'loginName':$("#loginName").val()
	    },
	    id: 'reloadTable'
	  });
}


	
	function search(sender){
		var loginName = $('#loginName');
	      //执行重载
	      table.reload('reloadTable', {
	        page: {
	          curr: 1 //重新从第 1 页开始
	        }
	        ,where: {
	        	loginName: loginName.val()
	        }
	      });
	      if(!isNull(sender)){
	    	  layMsg(sender,2000);
	      }
	      return false;
	}
	
	function toAppUserDetail(){
		var checkList = table.checkStatus('reloadTable').data;
		if(checkList.length==0||checkList.length>1){
			layMsg("请选择一条数据",2000);
			return false;
		}
		var id=checkList[0].id;
		perContent = layer.open({
	         type:2,
	         title: "APP用户详情",
	         content: '/appUser/toAppUserDetail?id='+id,
	         area: ['700px', '420px'],
	         maxmin: true,            //最大化按钮
	         anim:3,                    //动画
	         shade: [0.8, '#393D49'],//遮罩层
	         end: function(){
          }
	     });
    layer.full(perContent);
    return false;
	}
	
	
	
</script>
<style>
.layui-table-cell{
    height:23px;
    line-height:23px;
}
</style>
</body>
</html>